<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body style="height: 3000px;">
  <div id="app">
    <button @click="isShow=!isShow">{{isShow?'隐藏':'显示'}}</button>
    <home-page v-if="isShow"></home-page>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      data(){
        return {
          isShow: true
        }
      }
    })
    const HomePage = {
      template: `
        <div>
          <h2>首页</h2>  
        </div>
      `,
      data(){
        return {
          timer:null
        }
      },
     
      mounted(){
        this.timer = setInterval(() => {
          console.log(111);
        }, 1000)

        window.onscroll = function(){
          console.log('页面滚动了');
        }
      },
      beforeUnmount(){
        console.log('卸载之前-beforeUnmount');
        clearInterval(this.timer);
        window.onscroll = null;
      }
    }
    app.component('HomePage', HomePage)
    app.mount("#app")
  </script>
</body>
</html>